package ch.zbw.rre.stack;

public class StackVerketteteListe implements StackArray{

	
	private Node head;
	
	
	public StackVerketteteListe() {
		head = new Node();
	}

	@Override
	public boolean push(Element obj) {
		Node tempNode = null;
		tempNode = new Node();
		tempNode.setNext(head);
		tempNode.setItem(obj);
		head = tempNode;
			
		Element tempTest;
		tempTest = head.getItem();
		if (tempTest.getId() == obj.getId()){
			return true;
			
		}
		return false;
	}

	
	@Override
	public Element pop() {
		if((head.getItem() != null)&&(head.getNext() != null)){
			Element TempHead = head.getItem();
			Node tempNode = head.getNext();
			head = tempNode;
			return TempHead;
		}
		return null;
	}


	@Override
	public boolean empty() {
		if ((head.getItem() == null) && (head.getNext()== null))
		{
			return true;
		}
		return false;
	}

	@Override
	public Element top() {
		if((head.getItem() != null)&&(head.getNext() != null)){
			return head.getItem();
		}
		return null;
	}

}
